<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Files</a></li>
		<li><a href="#tabs-2">Editor</a></li>
	</ul>
	<div id="tabs-1">
		<div class="fsfiles">
			<div class="fsfile bold">
				<div class="file">{{!col_file}}</div>
				<div class="overrided">{{!col_overrided}}</div>
				<div class="type">{{!col_type}}</div>
				<div class="cl"></div>
			</div>
			{{foreach i in fsfiles}}
			<div class="fsfile">
				<div class="file">{{i.file}}</div>
				<div class="overrided"><img src="/shared/ajajform/style/checkbox{{if i.overrided}}A{{/if}}.png"/></div>
				<div class="type">{{i.type}}</div>
				<div class="path">{{i.path}}</div>
				<div class="cl"></div>
			</div>
			{{/foreach}}
		</div>
	</div>
	<div id="tabs-2">
		<textarea id="code-ta" name="data" style="width: 100%; height: 500px;"></textarea>
	</div>
</div>
<script>
$("#tabs").tabs();

$(".fsfile .file").bind("click",function(x) {
	load_code($(".path",this.parentNode).text(),$(this).text());
});
editAreaLoader.init({
	id: "code-ta",
	start_highlight: true,
	allow_resize: "both",
	allow_toggle: true,
	word_wrap: true,
	language: "en",
	is_multi_files: true,
	min_height: win_y()-200,
	toolbar: "save, |, search, go_to_line, |, undo, redo, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help",
	save_callback: "save_code"
});

function load_code(type,filename)
{
	$.ajax({
		type: "POST",
		url: "/admin-alltemplates/",
		data: {
			ajaj: 1,
			fsfile: type+"@"+filename,
			mode: "edit_ajaj"
		},
		success: function(ret) {
			std_response(ret);
		}
	});

}

function load_code2(ret)
{
	var new_file= {id: ret.type+"@"+ret.file, text: ret.data, syntax: ret.syntax, title: ret.file};
	editAreaLoader.openFile('code-ta', new_file);
	$("#tabs").tabs("select",1);
}

function save_code(id)
{
	var f=editAreaLoader.getCurrentFile(id);
//	alert("f.id="+f.id+"\nf.text="+f.text);
//	return;
	editAreaLoader.execCommand('code-ta', 'set_editable',0);
	$.ajax({
		type: "POST",
		url: "/admin-alltemplates/",
		data: {
			ajaj: 1,
			fsfile: f.id,
			mode: "save",
			data: f.text
		},
		success: function(ret) {
			editAreaLoader.execCommand('code-ta', 'set_editable',1);
			std_response(ret);
		}
	});
}

</script>
